import { YhBaseEntity, YhEntity } from "@/common/baseentity";
import { Column, Entity, Index, JoinColumn, ManyToOne, OneToMany, PrimaryColumn, RelationId, Tree, TreeChildren, TreeParent } from "typeorm";
import { BooleanType, FeeInOutType } from "@/common/type/enum";
import { decimalTransformer } from "@/common/transform/DecimalTransformer";
import { PortCntrStat } from "@/container/entities/container.entity";
@Entity({
    name: 'c_cntr_siz'
})
export class CntrSize extends YhEntity {
    @PrimaryColumn({
        type: 'char',
        name: 'cntr_siz_cod',
        comment: '箱尺寸代码',
        length: 2
    })
    cntr_siz_cod: string;

    @Column({
        type: 'decimal',
        name: 'cntr_teu',
        comment: 'TEU',
    })
    cntr_teu: number;
}


@Entity('c_cntr_typ')
export class CntrType extends YhEntity {
     @PrimaryColumn({
        type: 'char',
        name: 'cntr_typ_cod',
        comment: '箱类型代码',
        length: 2
    })
    cntr_typ_cod: string;

    @Column({
        type: 'varchar',
        name: 'cntr_typ_nam_c',
        comment: '箱类型名称',
    })
    cntr_typ_nam_c: string;

    @Column({
        type: 'enum',
        enum: BooleanType,
        name: 'part_id',
        comment: '是否箱组件',
    })
    part_id: BooleanType;

    @Column({
        type: 'enum',
        enum: BooleanType,
        name: 'reef_id',
        comment: '是否冷藏箱'
    })
    reef_id: BooleanType;

    @Column({
        type: 'decimal',
        name: 'stand_high',
        comment: '标准箱高'
    })
    stand_high: number;
 
}


/* @Entity({
    name: 'c_cy_cfs'
})
@Tree('materialized-path') */
@Entity({
    name: 'c_cy_cfs'
})
export class CyCfs extends YhBaseEntity {

    @Column({
        type: 'varchar',
        name: 'cfs_nam_c',
        comment: '站点名称'
    })
    cfs_nam_c: string;

    @Column({
        type: 'int',
        name: 'free_days',
        comment: '免堆天数'
    })
    free_days: number;

    @Column({
        type: 'decimal',
        name: 'stack_rate',
        comment: '堆存费率',
        transformer: decimalTransformer
    })
    stack_rate: number;
    
    @Column({
        type: 'varchar',
        name: 'country',
        comment: '国家'
    })
    country: string;

    @Column({
        type: 'varchar',
        name: 'linkman',
        comment: '联系人'
    })
    linkman: string;

    @Column({
        type: 'varchar',
        name: 'tel',
        comment: '电话'
    })
    tel: string;

    @Column({
        type: 'varchar',
        name: 'address',
        comment: '地址'
    })
    address: string;

    @Column({
        type: 'varchar',
        name: 'email',
        comment: '邮箱'
    })
    email: string;
    
   /*  @TreeChildren()
    children: CyCfs[];

    @TreeParent()
    parent: CyCfs;

    @RelationId((cfs: CyCfs) => cfs.parent)
    parentId: number;     */

    @OneToMany(() => PortCntrStat, (portcntrstat) => portcntrstat.Cfs)
    cntrStats: PortCntrStat[];

    @OneToMany(() => CfsStorageRate, (storagerate) => storagerate.cfs)
    storagerates: CfsStorageRate[];
}

@Entity({
    name: 'c_cfs_storage_rate'
})
export class CfsStorageRate extends YhBaseEntity {
    @Column({
        type: 'int',
        name: 'cfs_cod',
        comment: '站点ID'
    })
    cfs_cod: number;

    @Column({
        type: 'char',
        name: 'cntr_siz_cod',
        comment: '箱尺寸'
    })
    cntr_siz_cod: string;

    /* @Column({
        type: 'char',
        name: 'cntr_typ_cod',
        comment: '箱型'
    })
    cntr_typ_cod: string; */

    @Column({
        type: 'int',
        name: 'free_days',
        comment: '免费堆存天数'
    })
    free_days: number;

    @Column({
        type: 'decimal',
        name: 'rate',
        comment: '堆存费率',
        transformer: decimalTransformer
    })
    rate: number;

    @Column({
        type: 'varchar',
        name: 'currency_cod',
        comment: '货币'
    })
    currency_cod: string;
    
    @ManyToOne(() => CyCfs, (cycfs) => cycfs.storagerates)
    @JoinColumn({
        name: 'cfs_cod'
    })
    cfs: CyCfs;
}


@Entity({
    name: 'c_cy_cfs_area'
})
export class CyCfsArea extends YhBaseEntity {
    /* @Column({
        type: 'varchar',
        name: 'cfs_cod',
        comment: '站点'
    })
    cfs_cod: string; */

    @Column({
        type: 'int',
        name: 'cfs_cod',
        comment: '站点ID'
    })
    cfs_cod: number;

    @Column({
        type: 'varchar',
        name: 'cy_area',
        comment: '箱区'
    })
    cy_area: string;

   /*  @ManyToOne(() => CyCfs, (cfs) => cfs.areas)
    @JoinColumn({
        name: 'cfs_cod',
    })
    cfs: CyCfs; */

}

@Entity({
    name: 'c_client_cod'
})
export class Client extends YhBaseEntity {
    /* @Column({
        type: 'varchar',
        name: 'client_cod',
        comment: '客户代码'
    })
    client_cod: string; */

    @Column({
        type: 'varchar',
        name: 'client_nam_c',
        comment: '客户中文名称'
    })
    client_nam_c: string;

    @Column({
        type: 'varchar',
        name: 'client_nam_e',
        comment: '客户英文名称'
    })
    client_nam_e: string;

    @Column({
        type: 'varchar',
        name: 'client_short_c',
        comment: '中文简称'
    })
    client_short_c: string;

    @Column({
        type: 'varchar',
        name: 'client_short_e',
        comment: '英文简称'
    })
    client_short_e: string;

    @Column({
        type: 'enum',
        enum: BooleanType,
        name: 'trans_corp_id',
        comment: '运输公司标识'
    })
    trans_corp_id: BooleanType;

    @Column({
        type: 'enum',
        enum: BooleanType,
        name: 'provid_id',
        comment: '供应商标识'
    })
    provid_id: BooleanType;

    @Column({
        type: 'enum',
        enum: BooleanType,
        name: 'cntr_owner_id',
        comment: '箱主标识'
    })
    cntr_owner_id: BooleanType;

    @Column({
        type: 'enum',
        enum: BooleanType,
        name: 'repair_id',
        comment: '修箱公司标识'
    })
    repair_id: BooleanType;
    
    @Column({
        type: 'enum',
        enum: BooleanType,
        name: 'custom_id',
        comment: '客户标识'
    })
    custom_id: BooleanType;

    @Column({
        type: 'varchar',
        name: 'cfs_id',
        comment: '场站标识'
    })
    cfs_id: string;

    /* @Column({
        type: 'varchar',
        name: 'bank_nam',
        comment: '开户银行'
    })
    bank_nam: string;

    @Column({
        type: 'varchar',
        name: 'bank_account',
        comment: '银行账号'
    })
    bank_account: string;

    @Column({
        type: 'varchar',
        name: 'tax_no',
        comment: '税号'
    })
    tax_no: string; */
    
    @Column({
        type: 'varchar',
        name: 'email',
        comment: 'email地址'
    })
    email: string;

    @Column({
        type: 'varchar',
        name: 'client_nam_index',
        comment: '拼音索引'
    })
    client_nam_index: string;    // 根据客户中文名称 client_nam_c 转换

    @OneToMany(() => ClientBank, (clientbank) => clientbank.client)
    banks: ClientBank[];

}

@Entity({
    name: 'c_client_bank'
})
export class ClientBank extends YhBaseEntity {
    @Column({
        type: 'int',
        name: 'client_id',
        comment: '客户ID'
    })
    client_id: number;
    @Column({
        type: 'varchar',
        name: 'default_id',
        comment: '默认账号标识'
    })
    default_id: BooleanType
    @Column({
        type: 'varchar',
        name: 'bank_nam',
        comment: '开户银行'
    })
    bank_nam: string;

    @Column({
        type: 'varchar',
        name: 'bank_account',
        comment: '银行账号'
    })
    bank_account: string;

    @Column({
        type: 'varchar',
        name: 'tax_no',
        comment: '税号'
    })
    tax_no: string;
    
    @ManyToOne(() => Client, (client) => client.banks)
    @JoinColumn({
        name: 'client_id',
    })
    client: Client;
}
@Entity({
    name: 'c_plac_cod'
})
export class Place extends YhBaseEntity {
    @Column({
        type: 'varchar',
        name: 'plac_nam',
        comment: '地点名称'
    })
    plac_nam: string;

    @Column({
        type: 'varchar',
        name: 'plac_short',
        comment: '地点简称'
    })
    plac_short: string;

    @Column({
        type: 'decimal',
        name: 'distince',
        comment: '距离'
    })
    distince: number;
}

@Entity({
    name: 's_code'
})
export class Scode extends YhEntity {
    @PrimaryColumn({
        type: 'varchar',
        name: 'fld_eng',
        comment: '代码英文标识'
    })
    fld_eng: string;

    @PrimaryColumn({
        type: 'varchar',
        name: 'code',
        comment: '代码值'
    })
    code: string;

    @Column({
        type: 'varchar',
        name: 'fld_chi',
        comment: '代码中文标识'
    })
    fld_chi: string;

    @Column({
        type: 'varchar',
        name: 'name',
        comment: '代码值名称'
    })
    name: string;

    @Column({
        type: 'varchar',
        name: 'def_val',
        comment: '默认值'
    })
    def_val: string;
}

@Entity({
    name: 'c_cntr_stat'
})
export class CntrStat extends YhEntity {

    @PrimaryColumn({
        type: 'varchar',
        name: 'stat_cod',
        comment: '动态代码'
    })
    stat_cod: string;

    @Column({
        type: 'varchar',
        name: 'stat_nam',
        comment: '动态名称'
    })
    stat_nam: string;

    @Column({
        type: 'varchar',
        name: 'current_stat',
        comment: '箱状态'
    })
    current_stat: string;

    @Column({
        type: 'varchar',
        name: 'carry_id',
        comment: '收提标识'
    })
    carry_id: string;

    @Column({
        type: 'char',
        name: 'cal_stack',
        comment: '计算堆存费标识'
    })
    cal_stack: string;
    
    @Column({
        type: 'varchar',
        name: 'special_ope',
        comment: '删除动态时sql'
    })
    special_ope: string

    // 只绑定了next_stat_cod 暂未绑定stat_cod
    @OneToMany(() => CntrStatLogic, (statlogic) => statlogic.nextCntrStat)
    statlogic: CntrStatLogic[];
    
}

@Entity({
    name: 'cntr_stat_logic'
})
export class CntrStatLogic extends YhBaseEntity {
    @Column({
        type: 'varchar',
        name: 'stat_cod',
        comment: '当前动态'
    })
    stat_cod: string;

    @Column({
        type: 'varchar',
        name: 'next_stat_cod',
        comment: '下一步动态'
    })
    next_stat_cod: string;

    @ManyToOne(() => CntrStat, (cntrstat) => cntrstat.statlogic)
    @JoinColumn({
        name: 'next_stat_cod',
    })
    nextCntrStat: CntrStat;
}

@Entity({
    name: 'c_userquery_cfg'
})
export class UserQueryCfg extends YhBaseEntity {
    @Column({
        type: 'varchar',
        name: 'user_name',
        comment: '用户名称'
    })
    user_name: string;

    @Column({
        type: 'varchar',
        name: 'table_id',
        comment: 'web界面table-id'
    })
    table_id: string;

    @Column({
        type: 'varchar',
        name: 'item_name',
        comment: '查询项目名称'
    })
    item_name: string;

    @Column({
        type: 'json',
        name: 'cfg_json',
        comment: '配置明细'
    })
    cfg_json: object;

    
}

